bitkeeper revision 1.1106.1.1 (40faa752Kdxq9bbMRBdZigZQR4lssw)
authorkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Sun, 18 Jul 2004 16:37:38 +0000 (16:37 +0000)
committerkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Sun, 18 Jul 2004 16:37:38 +0000 (16:37 +0000)
Add iopl virtualisation to Linux 2.6. ioport.c is shared with 2.4.

.rootkeys
linux-2.4.26-xen-sparse/arch/xen/kernel/ioport.c [deleted file]
linux-2.4.26-xen-sparse/mkbuildtree
linux-2.6.7-xen-sparse/arch/xen/i386/kernel/ioport.c [new file with mode: 0644]
linux-2.6.7-xen-sparse/arch/xen/i386/kernel/process.c
linux-2.6.7-xen-sparse/arch/xen/i386/kernel/setup.c
linux-2.6.7-xen-sparse/include/asm-xen/asm-i386/processor.h

index 19a5f1a5ba10cd90c897e924041d8ae882bf6c8e..da6f19bddad8c385c7c7d17413c0561f44d91f81 100644 (file)
--- a/.rootkeys
+++ b/.rootkeys
@@ -80,7 +80,6 @@
 3e5a4e65ibVQmwlOn0j3sVH_j_6hAg linux-2.4.26-xen-sparse/arch/xen/kernel/evtchn.c
 3e5a4e65Hy_1iUvMTPsNqGNXd9uFpg linux-2.4.26-xen-sparse/arch/xen/kernel/head.S
 3e5a4e65RMGcuA-HCn3-wNx3fFQwdg linux-2.4.26-xen-sparse/arch/xen/kernel/i386_ksyms.c
-3e5a4e65MEvZhlr070sK5JsfAQlv7Q linux-2.4.26-xen-sparse/arch/xen/kernel/ioport.c
 3e5a4e653U6cELGv528IxOLHvCq8iA linux-2.4.26-xen-sparse/arch/xen/kernel/irq.c
 3e5a4e65muT6SU3ck47IP87Q7Ti5hA linux-2.4.26-xen-sparse/arch/xen/kernel/ldt.c
 4051db84bZeRX7a_Kh6VyyDuT5FOIg linux-2.4.26-xen-sparse/arch/xen/kernel/pci-dma.c
 40f56238xFQe9T7M_U_FItM-bZIpLw linux-2.6.7-xen-sparse/arch/xen/i386/kernel/evtchn.c
 40f56238bnvciAuyzAiMkdzGErYt1A linux-2.6.7-xen-sparse/arch/xen/i386/kernel/head.S
 40f58a0d31M2EkuPbG94ns_nOi0PVA linux-2.6.7-xen-sparse/arch/xen/i386/kernel/i386_ksyms.c
+40faa751_zbZlAmLyQgCXdYekVFdWA linux-2.6.7-xen-sparse/arch/xen/i386/kernel/ioport.c
 40f562382aC3_Gt4RG-4ZsfvDRUg3Q linux-2.6.7-xen-sparse/arch/xen/i386/kernel/irq.c
 40f56238ue3YRsK52HG7iccNzP1AwQ linux-2.6.7-xen-sparse/arch/xen/i386/kernel/ldt.c
 40f56238a8iOVDEoostsbun_sy2i4g linux-2.6.7-xen-sparse/arch/xen/i386/kernel/process.c
diff --git a/linux-2.4.26-xen-sparse/arch/xen/kernel/ioport.c b/linux-2.4.26-xen-sparse/arch/xen/kernel/ioport.c
deleted file mode 100644 (file)
index fc01640..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-#include <linux/sched.h>
-#include <linux/kernel.h>
-#include <linux/errno.h>
-#include <linux/types.h>
-#include <linux/stddef.h>
-#include <asm/hypervisor-ifs/dom0_ops.h>
-
-
-asmlinkage int sys_iopl(unsigned int new_io_pl)
-{
-    unsigned int old_io_pl = current->thread.io_pl;
-    dom0_op_t op;
-
-    if ( !(start_info.flags & SIF_PRIVILEGED) )
-        return -EPERM;
-
-    if ( new_io_pl > 3 )
-        return -EINVAL;
-
-    /* Need "raw I/O" privileges for direct port access. */
-    if ( (new_io_pl > old_io_pl) && !capable(CAP_SYS_RAWIO) )
-        return -EPERM;
-
-    /* Maintain OS privileges even if user attempts to relinquish them. */
-    if ( (new_io_pl == 0) && (start_info.flags & SIF_PRIVILEGED) )
-        new_io_pl = 1;
-
-    /* Change our version of the privilege levels. */
-    current->thread.io_pl = new_io_pl;
-
-    /* Force the change at ring 0. */
-    op.cmd           = DOM0_IOPL;
-    op.u.iopl.domain = DOMID_SELF;
-    op.u.iopl.iopl   = new_io_pl;
-    HYPERVISOR_dom0_op(&op);
-
-    return 0;
-}
-
-
-asmlinkage int sys_ioperm(unsigned long from, unsigned long num, int turn_on)
-{
-    printk(KERN_INFO "ioperm not fully supported - %s\n",
-           turn_on ? "set iopl to 3" : "ignore resource release");
-    return turn_on ? sys_iopl(3) : 0;
-}
-
-
index 1b86a3b4bffba1ee3c84484b5d2f2718b37f081f..5dba6c03d5259fcee7281c94388367b662899a8e 100755 (executable)
@@ -209,6 +209,7 @@ ln -sf ../../i386/kernel/pci-i386.h
 ln -sf ../../i386/kernel/ptrace.c
 ln -sf ../../i386/kernel/semaphore.c 
 ln -sf ../../i386/kernel/sys_i386.c 
+ln -sf ../../../${LINUX_26}/arch/xen/i386/kernel/ioport.c
 cd ../lib
 ln -sf ../../i386/lib/checksum.S 
 ln -sf ../../i386/lib/dec_and_lock.c 
diff --git a/linux-2.6.7-xen-sparse/arch/xen/i386/kernel/ioport.c b/linux-2.6.7-xen-sparse/arch/xen/i386/kernel/ioport.c
new file mode 100644 (file)
index 0000000..13b1cff
--- /dev/null
@@ -0,0 +1,49 @@
+#include <linux/sched.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/types.h>
+#include <linux/ioport.h>
+#include <linux/mm.h>
+#include <linux/smp.h>
+#include <linux/smp_lock.h>
+#include <linux/stddef.h>
+#include <linux/slab.h>
+#include <asm/hypervisor-ifs/dom0_ops.h>
+
+asmlinkage long sys_iopl(unsigned int new_io_pl)
+{
+       unsigned int old_io_pl = current->thread.io_pl;
+       dom0_op_t op;
+
+       if (!(start_info.flags & SIF_PRIVILEGED))
+               return -EPERM;
+
+       if (new_io_pl > 3)
+               return -EINVAL;
+
+       /* Need "raw I/O" privileges for direct port access. */
+       if ((new_io_pl > old_io_pl) && !capable(CAP_SYS_RAWIO))
+               return -EPERM;
+
+       /* Maintain OS privileges even if user attempts to relinquish them. */
+       if (new_io_pl == 0)
+               new_io_pl = 1;
+
+       /* Change our version of the privilege levels. */
+       current->thread.io_pl = new_io_pl;
+
+       /* Force the change at ring 0. */
+       op.cmd           = DOM0_IOPL;
+       op.u.iopl.domain = DOMID_SELF;
+       op.u.iopl.iopl   = new_io_pl;
+       HYPERVISOR_dom0_op(&op);
+
+       return 0;
+}
+
+asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
+{
+       printk(KERN_INFO "ioperm not fully supported - %s\n",
+               turn_on ? "set iopl to 3" : "ignore resource release");
+       return turn_on ? sys_iopl(3) : 0;
+}
index 1d7f637a669095c684b1cde4c5e0d5c809cceccb..c2642854feda064b40e9a34a0f30a1e190409557 100644 (file)
@@ -338,6 +338,7 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long esp,
        struct pt_regs * childregs;
        struct task_struct *tsk;
        int err;
+       unsigned long eflags;
 
        childregs = ((struct pt_regs *) (THREAD_SIZE + (unsigned long) p->thread_info)) - 1;
        struct_cpy(childregs, regs);
@@ -386,6 +387,10 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long esp,
                desc->b = LDT_entry_b(&info);
        }
 
+
+       __asm__ __volatile__ ( "pushfl; popl %0" : "=r" (eflags) : );
+       p->thread.io_pl = (eflags >> 12) & 3;
+
        err = 0;
  out:
        if (err && p->thread.io_bitmap_ptr)
@@ -532,6 +537,14 @@ struct task_struct fastcall * __switch_to(struct task_struct *prev_p, struct tas
         */
        load_TLS(next, cpu);
 
+       if (start_info.flags & SIF_PRIVILEGED) {
+               dom0_op_t op;
+               op.cmd           = DOM0_IOPL;
+               op.u.iopl.domain = DOMID_SELF;
+               op.u.iopl.iopl   = next->io_pl;
+               HYPERVISOR_dom0_op(&op);
+       }
+
        local_irq_restore(flags);
 
        /*
index 55a4a843d96cdae7a14047833851e53ab38a3885..097828f29c2fdc56939121c5715c4da77d67f9e2 100644 (file)
@@ -1206,6 +1206,17 @@ void __init setup_arch(char **cmdline_p)
        conswitchp = &dummy_con;
 #endif
 #endif
+
+       /* If we are a privileged guest OS then we should request IO privs. */
+       if (start_info.flags & SIF_PRIVILEGED) {
+               dom0_op_t op;
+               op.cmd           = DOM0_IOPL;
+               op.u.iopl.domain = DOMID_SELF;
+               op.u.iopl.iopl   = 1;
+               if (HYPERVISOR_dom0_op(&op) != 0)
+                       panic("Unable to obtain IOPL, despite SIF_PRIVILEGED");
+               current->thread.io_pl = 1;
+       }
 }
 
 #include "setup_arch_post.h"
index 6502baa35fc271fffd1382b552b6cc23b36785de..a57533dd8a19093fa71d762db226918996417699 100644 (file)
@@ -422,6 +422,7 @@ struct thread_struct {
        unsigned long   esp;
        unsigned long   fs;
        unsigned long   gs;
+       unsigned int    io_pl;
 /* Hardware debugging registers */
        unsigned long   debugreg[8];  /* %%db0-7 debug registers */
 /* fault info */